package hcom.model.board.dao;

import hcom.model.board.bean.BoardBean;

import java.util.List;
import com.ibatis.dao.client.DaoManager;
import ecg.dao.DaoService;

public class BoardDao {
	public static BoardDao instance;
	
	private DaoManager	manager = DaoService.getInstance();
	private IBoard		board	= (IBoard)manager.getDao(IBoard.class, "hcom");
	
	public static BoardDao getInstance() {
		if(instance == null) {
			synchronized(BoardDao.class) {
				if(instance == null) { instance = new BoardDao(); }
			}
		}
		return instance;
	}
	
	/**
	 * 게시판 목록 조회
	 * @param board_code
	 * @return
	 * @throws Exception
	 */
	public List<BoardBean> getBoardList(String board_code, String search, String searchKeyword, int startData, int endData) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setBoard_code(board_code);
		boardBean.setStartData(startData);
		boardBean.setEndData(endData);
		
		if(searchKeyword !=null && !searchKeyword.equals("")){
			boardBean.setSearchKeyword(searchKeyword);
		}
		
		if(search !=null && !search.equals("")){
			boardBean.setSearch(search);
		}
		
		return board.getBoardList(boardBean);
	}
	
	/**
	 * 메인 최신글 목록 조회
	 * @param board_code
	 * @return
	 * @throws Exception
	 */
	public List<BoardBean> getnewBoardList() throws Exception {
		BoardBean boardBean = new BoardBean();
				
		return board.getnewBoardList(boardBean);
	}
	/**
	 * 메인 최신글 목록 조회
	 * @param board_code
	 * @return
	 * @throws Exception
	 */
	public List<BoardBean> getlibBoardList() throws Exception {
		BoardBean boardBean = new BoardBean();
				
		return board.getlibBoardList(boardBean);
	}
	
	/**
	 * 소송게시판 목록 조회
	 * @param board_code
	 * @return
	 * @throws Exception
	 */
	public List<BoardBean> getCaseList(String search, String searchKeyword, int startData, int endData, String search_field, String search_text) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setStartData(startData);
		boardBean.setEndData(endData);
		
		if(searchKeyword !=null && !searchKeyword.equals("")){
			boardBean.setSearchKeyword(searchKeyword);
		}
		
		if(search !=null && !search.equals("")){
			boardBean.setSearch(search);
		}
		
		if(search_field !=null && !search_field.equals("")){
			boardBean.setSearch_field(search_field);
		}
		
		if(search_text !=null && !search_text.equals("")){
			boardBean.setSearch_text(search_text);
		}
		
		return board.getCaseList(boardBean);
	}
	
	
	public List<BoardBean> getCasepotalList(String search, String searchKeyword, int startData, int endData, String search_field, String search_text) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setStartData(startData);
		boardBean.setEndData(endData);
		
		if(searchKeyword !=null && !searchKeyword.equals("")){
			boardBean.setSearchKeyword(searchKeyword);
		}
		
		if(search !=null && !search.equals("")){
			boardBean.setSearch(search);
		}
		
		if(search_field !=null && !search_field.equals("")){
			boardBean.setSearch_field(search_field);
		}
		
		if(search_text !=null && !search_text.equals("")){
			boardBean.setSearch_text(search_text);
		}
		
		return board.getCasepotalList(boardBean);
	}
	
	/**
	 * 게시판 목록 갯수
	 * @param board_code
	 * @return
	 * @throws Exception
	 */
	public int getBoardCount(String board_code) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setBoard_code(board_code);
		
		return board.getBoardCount(boardBean);
	}
	/**
	 * 소송게시판 목록 갯수
	 * @param board_code
	 * @return
	 * @throws Exception
	 */
	public int getCaseCount(BoardBean boardBean) throws Exception {
		return board.getCaseCount(boardBean);
	}
	
	/**
	 * 게시판 상세보기
	 * @param board_seq
	 * @return
	 * @throws Exception
	 */
	public BoardBean getBoardView(int board_seq) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setBoard_seq(board_seq);
		
		return board.getBoardView(boardBean);
	}
	
	/**
	 * 소송 상세보기
	 * @param board_seq
	 * @return
	 * @throws Exception
	 */
	public BoardBean getcaseView(int case_seq,String mem_dept) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setCase_seq(case_seq);
		boardBean.setMem_dept(mem_dept);
		return board.getcaseView(boardBean);
	}
	
	public BoardBean getcaseDetail(int case_seq,String court_step) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setCase_seq(case_seq);
		boardBean.setCourt_step(court_step);
		return board.getcaseDetail(boardBean);
	}

	public BoardBean casegetseq(int case_seq) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setCase_seq(case_seq);
		
		return board.casegetseq(boardBean);
	}
	
	public BoardBean getContentDetail(int case_seq,String court_step,int log_seq) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setCase_seq(case_seq);
		boardBean.setCourt_step(court_step);
		boardBean.setLog_seq(log_seq);
		
		return board.getContentDetail(boardBean);
	}
	
	public void insertlogseq(int case_seq,String court_step) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setCase_seq(case_seq);
		boardBean.setCourt_step(court_step);
				
		board.insertlogseq(boardBean);
	}
	
	
	public List<BoardBean> getCase(int case_seq,String Court_step) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setCase_seq(case_seq);
		boardBean.setCourt_step(Court_step);
		return board.getCase(boardBean);
		
	}
	/**
	 * 조회수 증가
	 * @param board_seq
	 * @param count
	 * @throws Exception
	 */
	public void increaseCount(int board_seq, int count) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setBoard_seq(board_seq);
		boardBean.setRead_count(count);
		
		board.increaseCount(boardBean);
	}
	
	/**
	 * 글 등록
	 * @param boardBean
	 * @throws Exception
	 */
	public void insertBoard(BoardBean boardBean) throws Exception {
		board.insertBoard(boardBean);
	}
	
	/**
	 * 소송글 등록
	 * @param boardBean
	 * @throws Exception
	 */
	public void insertCase(BoardBean boardBean) throws Exception {
		board.insertCase(boardBean);
	}
	
	public void casecourt(int case_seq) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setCase_seq(case_seq);
		board.casecourt(boardBean);
	}
	public void casecourt2(int case_seq) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setCase_seq(case_seq);
		board.casecourt2(boardBean);
	}
	
	public void casecourt3(int case_seq) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setCase_seq(case_seq);
		board.casecourt3(boardBean);
	}
	
	
	/**
	 * 심급별 등록
	 * @param boardBean
	 * @throws Exception
	 */
	public void updateCasecourt(BoardBean boardBean) throws Exception {
		board.updateCasecourt(boardBean);
	}
	
	
	public void insertContent(BoardBean boardBean) throws Exception {
		board.insertContent(boardBean);
	}
	

	/**
	 * 주요내용 심급 목록 
	 * @param board_code
	 * @return
	 * @throws Exception
	 */
	public BoardBean getContent(int Case_seq) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setCase_seq(Case_seq);
		return board.getContent(boardBean);
	}
	
	/**
	 * 글 삭제
	 * @param board_seq
	 * @throws Exception
	 */
	public void deleteBoard(int board_seq) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setBoard_seq(board_seq);
		
		board.deleteBoard(boardBean);
	}

	/**
	 * 글 수정
	 * @param boardBean
	 * @throws Exception
	 */
	public void updateBoard(BoardBean boardBean) throws Exception {
		board.updateBoard(boardBean);
	}
	
	public void updateContent(BoardBean boardBean) throws Exception {
		board.updateContent(boardBean);
	}
	
	public void caseupdate(BoardBean boardBean) throws Exception {
		board.caseupdate(boardBean);
	}
	
	public void caseupdate1(BoardBean boardBean) throws Exception {
		board.caseupdate1(boardBean);
	}
	
	public void caseDeletego(BoardBean boardBean) throws Exception {
		board.caseDeletego(boardBean);
	}
	public void caseDelete2(BoardBean boardBean) throws Exception {
		board.caseDelete2(boardBean);
	}
	
	public void casecourtDelete(BoardBean boardBean) throws Exception {
		board.casecourtDelete(boardBean);
	}
	
	public void caselogDelete(BoardBean boardBean) throws Exception {
		board.caselogDelete(boardBean);
	}

	public void casedeletepop(BoardBean boardBean) throws Exception {
		board.casedeletepop(boardBean);
	}
	
	
	/**
	 * 파일 보기
	 * @param board_seq
	 * @return
	 * @throws Exception
	 */
	public BoardBean getFile(int board_seq, String save_type) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setBoard_seq(board_seq);
		boardBean.setSave_type(save_type);
		
		return board.getFile(boardBean);
	}
	
	public BoardBean getcaseFile(int Case_seq, String Court_step, int Log_seq) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setCase_seq(Case_seq);
		boardBean.setLog_seq(Log_seq);
		boardBean.setCourt_step(Court_step);
		
		return board.getcaseFile(boardBean);
	}
	
  public BoardBean getoneFile(int board_seq, String save_type)
	    throws Exception
	  {
	    BoardBean boardBean = new BoardBean();
	    boardBean.setBoard_seq(board_seq);
	    boardBean.setSave_type(save_type);

	    return this.board.getoneFile(boardBean);
	  }
	
	/**
	 * 파일 등록
	 * @param boardBean
	 * @throws Exception
	 */
	public void insertFile(BoardBean boardBean) throws Exception {
		board.insertFile(boardBean);
	}
	
	public void insertcaseFile(BoardBean boardBean) throws Exception {
		board.insertcaseFile(boardBean);
	}
	
	
	/**
	 * 파일 수정
	 * @param boardBean
	 * @throws Exception
	 */
	public void updateFile(BoardBean boardBean) throws Exception {
		board.updateFile(boardBean);
	}
	
	/**
	 * 파일 삭제
	 * @param attach_seq
	 * @throws Exception
	 */
	public void deleteFile(BoardBean boardBean) throws Exception {
		board.deleteFile(boardBean);
	}
	
	public void casedeleteFile(BoardBean boardBean) throws Exception {
		board.casedeleteFile(boardBean);
	}
	
	/**
	 * 답변 등록
	 * @param boardBean
	 * @throws Exception
	 */
	public void insertAnswer(BoardBean boardBean) throws Exception {
		board.insertAnswer(boardBean);
	}
	
	/**
	 * 답변 수정
	 * @param boardBean
	 * @throws Exception
	 */
	public void updateAnswer(BoardBean boardBean) throws Exception {
		board.updateAnswer(boardBean);
	}
	
	/**
	 * 답변 삭제
	 * @param board_seq
	 * @throws Exception
	 */
	public void deleteAnswer(int board_seq) throws Exception {
		BoardBean boardBean = new BoardBean();
		boardBean.setBoard_seq(board_seq);
		
		board.deleteAnswer(boardBean);
	}
	
	/**
	 * 최근 저장한 글 번호
	 * @return
	 * @throws Exception
	 */
	public BoardBean getTopBoardSeq() throws Exception {
		return board.getTopBoardSeq();
	}
	
	/**
	 * 최근 저장한 글 번호
	 * @return
	 * @throws Exception
	 */
	public BoardBean getTopCaseSeq() throws Exception {
		return board.getTopCaseSeq();
	}
	
	public BoardBean getToplogSeq() throws Exception {
		return board.getToplogSeq();
	}

	public BoardBean getFileDown(int board_seq, String save_type, int attach_seq) {
		BoardBean boardBean = new BoardBean();
		boardBean.setBoard_seq(board_seq);
		boardBean.setSave_type(save_type);
		boardBean.setAttach_seq(attach_seq);
		
		return board.getFileDown(boardBean);
	}
	
	public BoardBean getFilecaseDown(int Case_seq, int Log_seq, String Court_step, int attach_seq) {
		BoardBean boardBean = new BoardBean();
		boardBean.setCase_seq(Case_seq);
		boardBean.setLog_seq(Log_seq);
		boardBean.setCourt_step(Court_step);
		boardBean.setAttach_seq(attach_seq);
		
		return board.getFilecaseDown(boardBean);
	}


	public List<BoardBean> getAttachNumList(String board_seq) {
		BoardBean boardBean = new BoardBean();
		boardBean.setBoard_seq(Integer.parseInt(board_seq));
		
		return board.getAttachNumList(boardBean);
	}
	
	public List<BoardBean> AttachNumList(String log_seq) {
		BoardBean boardBean = new BoardBean();
		boardBean.setLog_seq(Integer.parseInt(log_seq));
		
		return board.AttachNumList(boardBean);
	}
}

